﻿<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <!--作为公共模版分离出去-->
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="admin/images/rookieCs.ico" />
    <link rel="Shortcut Icon" href="admin/images/rookieCs.ico" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui/css/H-ui.my.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/css/h-ui.admin.pro.iframe.min.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/Hui-iconfont/1.0.9/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/lc_switch/20160127/css/lc_switch.css" />
    <link rel="stylesheet" type="text/css" href="admin/css/iconfont/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="admin/css/mywork.css" />
    <script type="text/javascript" src="admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="admin/lib/layer/3.1.1/layer.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/plugins/datagrid-detailview.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="admin/lib/lc_switch/20160127/js/lc_switch.min.js"></script>
    <script>document.write('<script type="text/javascript" src="admin/js/common.js?v='+ Date.now() +'"><\/script>');</script>
    <script>document.write('<script type="text/javascript" src="admin/js/formatter.js?v='+ Date.now() +'"><\/script>');</script>
    <!--作为公共模版分离出去-->
    <title>消息列表</title>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%;font-family: 微软雅黑,serif" memuId="message-list">
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en" style="float: none">&gt;</span> 消息管理
    <span class="c-gray en" style="float: none">&gt;</span> 消息列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<!--按钮元素-->
<div id="buttonInfo" class="buttonInfo">
    <button class="easyui-linkbutton" onclick="addMessage()"><i class="Hui-iconfont">&#xe600;</i>新增</button>
    <button class="easyui-linkbutton" onclick="editMessage()"><i class="Hui-iconfont">&#xe6df;</i>修改</button>
    <button class="easyui-linkbutton" onclick="delMessage()"><i class="Hui-iconfont">&#xe6e2;</i>删除</button>
</div>
<!--查询条件元素-->
<div id="searchInfo" class="searchInfo">
    <div class="searchLabel">消息内容：<span id="s_content"></span></div>
    <div class="searchLabel">发送人ID：<span id="s_send_userid"></span></div>
    <div class="searchLabel">发送时间：<span id="s_send_date"></span></div>
    <div class="searchLabel">接收人ID：<span id="s_receive_userid"></span></div>
    <div class="searchLabel">状态：<span id="s_status"></span></div>
    <a id="searchBtn" onclick="query(pageParam, true)"></a>
</div>
<!--表格元素-->
<div id="tableInfo"></div>
<script type="text/javascript">
    //准备函数
    $(function () {
        initSearchForm();
        initGrid();
        getGridHidden("tableInfo");
        query(pageParam);
    });

    //查询条件初始化
    function initSearchForm() {
        $("#s_content").textbox({
            width: 150,
            prompt: "请输入消息内容"
        });
        $("#s_send_userid").combobox({
            width: 120,
            prompt: "请选择发送人",
            panelHeight: "auto",
            valueField: "id",
            textField: "name",
            editable: true,
            url: "user/getUserListByRoleCode",
            queryParams: {roleCode: "ALL"},
            loadFilter: function (data) {
                var temp = data.bizData;
                temp.unshift({"id":-1, "name":"全部", selected:true});
                return temp;
            }
        });
        $("#s_send_date").datebox({
            width: 120,
            prompt: "请选择发送日期",
            editable: false
        });
        $("#s_receive_userid").combobox({
            width: 120,
            prompt: "请选择接收人",
            panelHeight: "auto",
            valueField: "id",
            textField: "name",
            editable: true,
            url: "user/getUserListByRoleCode",
            queryParams: {roleCode: "ALL"},
            loadFilter: function (data) {
                var temp = data.bizData;
                temp.unshift({"id":-1, "name":"全部", selected:true});
                return temp;
            }
        });
        $("#s_status").combobox({
            width: 120,
            prompt: "请选择状态",
            panelHeight: "auto",
            data: message_status_data_all
        });
        $("#s_status").combobox("setValue", 1);
        $("#searchBtn").linkbutton({
            text: '查询',
            plain: "true",
            iconCls: 'icon-search'
        });
    }

    //表格元素初始化
    function initGrid() {
        $("#tableInfo").datagrid({
            pagination: true,
            singleSelect: false,
            fitColumns: true,
            striped: true,
            fit: true,
            columns: [[
                {field: "ck", checkbox: "true"},
                {field: "id", title: "编号", width: 60, align: "center", sortable: true},
                {field: "content", title: "消息内容", width: 500, align: "left", sortable: true, formatter: message_content_formatter},
                {field: "send_username", title: "发送人", width: 100, align: "center", sortable: true},
                {field: "send_date", title: "发送时间", width: 140, align: "center", sortable: true, formatter: message_send_date_formatter},
                {field: "receive_username", title: "接收人", width: 100, align: "center", sortable: true},
                {field: "status", title: "状态", width: 100, align: "center", sortable: true, formatter: message_status_formatter},
                {field: "oper", title: "操作", width: 80, align: "center",
                    formatter: function (value, row) {
                        return row.status == 1 ? ('<a style="text-decoration:none" onClick="readMessage(\''+ row.id + '\')" title="设置为已读"><i class="Hui-iconfont">&#xe631;</i></a>') : '';
                    }
                }
            ]],
            //表格工具栏元素ID
            toolbar: ".breadcrumb, #buttonInfo, #searchInfo",
            onSortColumn: function (sort,order) {
                pageParam.pageNo = 1;
                pageParam.sort = sort;
                pageParam.order = order;
                query(pageParam);
            },
            onSelect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onSelectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onLoadSuccess: function (data) {
                toolBarBtnDisabledById([false, true, true], "buttonInfo");
            }
        }).pagination({
            total: 0,
            rows: 0,
            pageNumber: pageParam.pageNo,
            pageSize: pageParam.pageSize,
            pageList: Page.getPageList(),
            buttons: [
                {text: "个性化设置", iconCls: "icon-tip", handler: function() {selectColumnMenu("tableInfo");}}
            ],
            onBeforeRefresh : function() {},
            onSelectPage: function(pageNumber, pageSize) {
                pageParam.pageNo = pageNumber;
                pageParam.pageSize = pageSize;
                query(pageParam);
            },
            onChangePageSize: function(pageSize) {
                pageParam.pageSize = pageSize;
            }
        });
        //表格事件
        var selectedTableRow = function() {
            var selectRow = $("#tableInfo").datagrid("getSelections");
            if (selectRow.length == 0) {
                toolBarBtnDisabledById([false, true, true], "buttonInfo");
            } else if (selectRow.length == 1) {
                toolBarBtnDisabledById([false, false, false], "buttonInfo");
            } else {
                toolBarBtnDisabledById([false, true, false], "buttonInfo");
            }
        };
    }

    //获取用户个性化设置
    function getGridHidden() {
        ajaxPostFun("userMenuHidden/getUserMenuHidden", {menu_id: $("body").attr("memuId"), grid_id: "tableInfo"}, function(bizData) {
            for (var i in bizData) {
                $("#tableInfo").datagrid("hideColumn", bizData[i].grid_col);
            }
        }, null, "获取用户个性化设置");
    }

    //分页查询
    function query(pageParam, goHead) {
        pageParam.content = $("#s_content").textbox("getValue").trim();
        pageParam.send_userid = $("#s_send_userid").combobox("getValue");
        pageParam.send_date = $("#s_send_date").datebox("getValue");
        pageParam.receive_userid = $("#s_receive_userid").combobox("getValue");
        pageParam.status = $("#s_status").combobox("getValue");
        if (goHead && goHead)
            pageParam.pageNo = 1;
        var successFun = function(bizData) {
            $("#tableInfo").datagrid("loadData", bizData.rows);
            $("#tableInfo").datagrid("getPager").pagination({pageNumber: bizData.page, total: bizData.records});
        };
        var errorFun = function() {
            showFailedMsg("查询数据出错");
        };
        ajaxGetFun("message/queryPage", pageParam, successFun, errorFun, "获取消息列表");
    }

    //新增
    function addMessage() {
        var openedFun = function () {};
        var saveFun = function(index, layero) {
            var formEle = layero.find("iframe")[0].contentWindow.$("#formInfo");
            if (formEle.form("validate")) {
                var messageInfo = getFormJson(formEle);
                var successFun = function(bizData) {
                    layer.close(index);
                    query(pageParam, true);
                    showSuccessMsg("新增成功");
                };
                ajaxPostFun("message/saveInfo", messageInfo, successFun, null, "新建消息");
            }
        };
        openIframe(false, 500, 260, "message-info.html", openedFun, saveFun);
    }

    //修改
    function editMessage() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length != 1) {
            return showWarnMsg("请选择一条条目后操作");
        }
        var openedFun = function (index, layero) {
            $("iframe")[0].contentWindow.$("#formInfo").form("load", selectRows[0])
        };
        var saveFun = function(index, layero) {
            var formEle = layero.find("iframe")[0].contentWindow.$("#formInfo");
            if (formEle.form("validate")) {
                var messageInfo = getFormJson(formEle);
                var successFun = function(bizData) {
                    layer.close(index);
                    query(pageParam, true);
                    showSuccessMsg("修改成功");
                };
                ajaxPostFun("message/updateInfo", messageInfo, successFun, null, "修改消息");
            }
        };
        openIframe(false, 500, 260, "message-info.html", openedFun, saveFun);
    }

    //删除
    function delMessage() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length == 0) {
            return showWarnMsg("请选择条目后操作");
        }
        var ids = mergedRowCell(selectRows, "id");
        layer.confirm('确认要删除选中的消息吗？', function(index) {
            var successFun = function(bizData) {
                showSuccessMsg("已删除"+ bizData +"条数据");
                query(pageParam, true);
            };
            ajaxPostFun("message/deleteInfoByIds", {ids: ids}, successFun, null, "删除消息");
        });
    }

    //设置为已读
    function readMessage(messageId) {
        var successFun = function(bizData) {
            showSuccessMsg("操作成功");
            query(pageParam, true);
        };
        ajaxPostFun("message/readMessage", {messageId: messageId}, successFun, null, "设置消息已读");
    }
</script> 
</body>
</html>